home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-30 | 9.7 KB | 465 lines | [TEXT/CWIE] |
- { EditText.p }
- { Created 10/30/98 1:06 PM by AppMaker }
-
- Unit EditText;
- Interface
-
- Uses
- Types,
- Quickdraw,
- Controls,
- Dialogs,
- Events,
- Lists,
- Menus,
- Resources,
- TextEdit,
- ToolUtils,
-
- DDocData,
- EverythingEngine,
- EverythingDoc,
- AMWindow;
-
- type
- EditText = object (AMWindow)
-
- {data members}
- mData: DDocData;
- mSmallHandle: ControlHandle;
- mLargeHandle: ControlHandle;
- mX12345Handle: ControlHandle;
- mX12345e6Handle: ControlHandle;
- mPasswordHandle: ControlHandle;
- mDateHandle: ControlHandle;
- mTimeHandle: ControlHandle;
- mStyledHandle: ControlHandle;
-
- {methods}
- Procedure Initialize; Override;
-
- Procedure Open (inDoc: EverythingDoc;
- inData: DDocData);
- Procedure Close; Override;
-
- Procedure Control (whichControl: ControlHandle;
- whichPart: integer;
- where: Point); Override;
- Procedure MouseIn (where: Point;
- modifiers: integer); Override;
- Procedure TypeIn (charCode: SInt16); Override;
- Procedure ExitCurField; Override;
- Procedure DataChanged (inDataID: longint); Override;
- Procedure Resize; Override;
- Procedure Scroll (newValue: integer;
- oldValue: integer); Override;
-
- Function GetEngine: EverythingEngine;
-
- {$ifc false}
- Procedure UpdateMenus; Override;
- {$endif}
- Function DoCommand (inCommand: longint): Boolean; Override;
-
- Procedure DoUndo;
- Procedure DoCut;
- Procedure DoCopy;
- Procedure DoPaste;
- Procedure DoClear;
- Procedure DoSelectAll;
- Procedure DoShowClipboard;
-
- end;
-
- {----------}
- Procedure CreateEditText (inDoc: EverythingDoc;
- inData: DDocData);
-
- {----------}
- Implementation
-
- Uses
- Globals,
- ResourceDefs,
- DoScrap,
- Scrolling,
- ControlUtils,
- Miscellany;
-
- const
- kSmallField = 1;
- kLargeField = 2;
- kX12345Field = 3;
- kX12345e6Field = 4;
- kPasswordField = 5;
- kDateField = 6;
- kTimeField = 7;
- kStyledField = 8;
-
- {----------}
- Procedure CreateEditText (
- inDoc: EverythingDoc;
- inData: DDocData);
- var
- winObj: EditText;
- begin
- winObj := nil;
- New (winObj);
-
- if winObj <> nil then begin
- winObj.Initialize;
- winObj.Open (inDoc, inData);
- end;
- end;
-
- {----------}
- Procedure EditText.Initialize;
- begin
- Inherited Initialize;
- end;
-
- {----------}
- Function EditText.GetEngine: EverythingEngine;
- begin
- GetEngine := EverythingEngine (mDoc.mEngine);
- end;
-
- {----------}
- Procedure EditText.Open (
- inDoc: EverythingDoc;
- inData: DDocData);
- var
- window: WindowPtr;
- wftb: Handle;
- errCode: OSErr;
- begin
- mDoc := inDoc;
- mData := inData;
- mData.AddResponder (self);
-
- window := GetNewCWindow (WIND_EditText, nil, WindowPtr (-1));
- if inDoc.mEngine.GetFilename <> '' then begin
- SetWTitle (window, inDoc.mEngine.GetFilename);
- end;
- mWindow := window;
- EverythingDoc (mDoc).mEditTextPtr := window;
-
- WindowPeek (window)^.windowKind := kAMWindowFlag;
- SetWRefCon (window, ord4 (self));
- SetPort (window);
- SetInfo (window);
-
- wftb := GetResource ('Wftb', WIND_EditText);
-
- errCode := CreateRootControl (window, mRootControl);
-
- vScroll := nil;
- hScroll := nil;
-
-
- mSmallHandle := GetNewControl (CNTL_Small, window);
- SetWindowItemFont (mSmallHandle, wftb, 1);
- SetControlText (mSmallHandle, mData.GetSmall);
-
- mLargeHandle := GetNewControl (CNTL_Large, window);
- SetWindowItemFont (mLargeHandle, wftb, 2);
- SetControlText (mLargeHandle, mData.GetLarge);
-
- mX12345Handle := GetNewControl (CNTL_X12345, window);
- SetWindowItemFont (mX12345Handle, wftb, 3);
- SetControlTextValue (mX12345Handle, mData.GetX12345);
-
- mX12345e6Handle := GetNewControl (CNTL_X12345e6, window);
- SetWindowItemFont (mX12345e6Handle, wftb, 4);
- SetControlTextFloat (mX12345e6Handle, mData.GetX12345e6);
-
- mPasswordHandle := GetNewControl (CNTL_Password, window);
- SetWindowItemFont (mPasswordHandle, wftb, 5);
- SetControlText (mPasswordHandle, mData.GetPassword);
-
- mDateHandle := GetNewControl (CNTL_Date, window);
- SetWindowItemFont (mDateHandle, wftb, 6);
- SetClockDateTime (mDateHandle, mData.GetTheDate);
-
- mTimeHandle := GetNewControl (CNTL_Time, window);
- SetWindowItemFont (mTimeHandle, wftb, 7);
- SetClockDateTime (mTimeHandle, mData.GetTheTime);
-
- mStyledHandle := GetNewControl (CNTL_Styled, window);
- SetWindowItemFont (mStyledHandle, wftb, 8);
- SetControlText (mStyledHandle, mData.GetStyled);
-
- errCode := AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- end;
-
- {----------}
- Procedure EditText.Close;
- begin
- mData.RemoveResponder (self);
-
- EverythingDoc (mDoc).mEditTextPtr := nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- Dispose (self);
- end;
-
- {----------}
- Procedure EditText.Control (
- whichControl: ControlHandle;
- whichPart: integer;
- where: Point);
- var
- bounds: Rect;
- newValue: integer;
- partcode: SInt16;
- begin
- ExitCurField ();
-
- if whichControl = mSmallHandle then begin
- HandleEditClick (mSmallHandle, where);
- end;
- if whichControl = mLargeHandle then begin
- HandleEditClick (mLargeHandle, where);
- end;
- if whichControl = mX12345Handle then begin
- HandleEditClick (mX12345Handle, where);
- end;
- if whichControl = mX12345e6Handle then begin
- HandleEditClick (mX12345e6Handle, where);
- end;
- if whichControl = mPasswordHandle then begin
- HandleEditClick (mPasswordHandle, where);
- end;
- if whichControl = mDateHandle then begin
- HandleEditClick (mDateHandle, where);
- end;
- if whichControl = mTimeHandle then begin
- HandleEditClick (mTimeHandle, where);
- end;
- if whichControl = mStyledHandle then begin
- HandleEditClick (mStyledHandle, where);
- end;
- end;
-
- {----------}
- Procedure EditText.DataChanged (
- inDataID: longint);
- begin
- if inDataID = idSmall then begin
- SetControlText (mSmallHandle, mData.GetSmall);
- end;
- if inDataID = idLarge then begin
- SetControlText (mLargeHandle, mData.GetLarge);
- end;
- if inDataID = idX12345 then begin
- SetControlTextValue (mX12345Handle, mData.GetX12345);
- end;
- if inDataID = idX12345e6 then begin
- SetControlTextFloat (mX12345e6Handle, mData.GetX12345e6);
- end;
- if inDataID = idPassword then begin
- SetControlText (mPasswordHandle, mData.GetPassword);
- end;
- if inDataID = idTheDate then begin
- SetClockDateTime (mDateHandle, mData.GetTheDate);
- end;
- if inDataID = idTheTime then begin
- SetClockDateTime (mTimeHandle, mData.GetTheTime);
- end;
- if inDataID = idStyled then begin
- SetControlText (mStyledHandle, mData.GetStyled);
- end;
- End;
-
- {----------}
- Procedure EditText.MouseIn (
- where: Point;
- modifiers: integer);
- var
- bounds: Rect;
- begin
- end;
-
- {----------}
- Procedure EditText.ExitCurField;
- var
- errCode: OSErr;
- focus: ControlHandle;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- if focus = nil then begin
- { nothing to exit }
-
- end else if focus = mSmallHandle then begin
- mData.SetSmall (GetEditTextStr (mSmallHandle));
- end else if focus = mLargeHandle then begin
- mData.SetLarge (GetEditTextChars (mLargeHandle));
- end else if focus = mX12345Handle then begin
- mData.SetX12345 (GetControlTextValue (mX12345Handle));
- end else if focus = mX12345e6Handle then begin
- mData.SetX12345e6 (GetControlTextFloat (mX12345e6Handle));
- end else if focus = mPasswordHandle then begin
- mData.SetPassword (GetEditTextPasswordStr (mPasswordHandle));
- end else if focus = mDateHandle then begin
- mData.SetTheDate (GetClockDateTime (mDateHandle));
- end else if focus = mTimeHandle then begin
- mData.SetTheTime (GetClockDateTime (mTimeHandle));
- end else if focus = mStyledHandle then begin
- mData.SetStyled (GetEditTextChars (mStyledHandle));
- end;
- inherited ExitCurField;
- end;
-
- {----------}
- Procedure EditText.TypeIn (
- charCode: SInt16);
- var
- ch: char;
- errCode: OSErr;
- focus: ControlHandle;
- keyCode: SInt16;
- partcode: SInt16;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- ch := chr (charCode);
- if (ch = charEnter)
- | (ch = charReturn) then begin
- ExitCurField;
- end else if ch = charEsc then begin
- end else if ch = charTab then begin
- DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
- end else if focus <> nil then begin
- keyCode := BAnd (curEvent.message, keyCodeMask);
- partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
- mDoc.mEngine.SetDirty;
- end else begin
- SysBeep (1);
- end;
- end;
-
- {----------}
- Procedure EditText.Resize;
- begin
- { application-specific code to resize items in window }
- end;
-
- {----------}
- Procedure EditText.Scroll (
- newValue: integer;
- oldValue: integer);
- begin
- { application-specific code to scroll window }
- if gWhichScroll = vScroll then begin
- end else begin { horizontal }
- end;
- end;
-
- {----------}
- Procedure EditText.DoUndo;
- begin
- end; {DoUndo}
-
- {----------}
- Procedure EditText.DoCut;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECut (curTE);
- mDoc.mEngine.SetDirty;
- scrapDirty := true;
- end;
- end; {DoCut}
-
- {----------}
- Procedure EditText.DoCopy;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECopy (curTE);
- scrapDirty := true;
- end;
- end; {DoCopy}
-
- {----------}
- Procedure EditText.DoPaste;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEPaste (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoPaste}
-
- {----------}
- Procedure EditText.DoClear;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEDelete (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoClear}
-
- {----------}
- Procedure EditText.DoSelectAll;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TESetSelect (0, 32767, curTE);
- end;
- end; {DoSelectAll}
-
- {----------}
- Procedure EditText.DoShowClipboard;
- begin
- end; {DoShowClipboard}
-
- {----------}
- Function EditText.DoCommand (
- inCommand: longint): Boolean;
- begin
- DoCommand := true;
- case inCommand of
- cmdUndo:
- DoUndo;
- cmdCut:
- DoCut;
- cmdCopy:
- DoCopy;
- cmdPaste:
- DoPaste;
- cmdClear:
- DoClear;
- cmdSelectAll:
- DoSelectAll;
- cmdShowClipboard:
- DoShowClipboard;
-
- otherwise
- DoCommand := false;
- end; {case}
- end;
-
- end.
-